//
//  CellOfGuid.m
//  Project_A
//
//  Created by dllo on 16/2/25.
//  Copyright © 2016年 dllo. All rights reserved.
//

#import "CellOfzhuyi.h"
#import "ModelOfzhuyi.h"

#import <DKNightVersion.h>
#define WIDTH [UIScreen mainScreen].bounds.size.width
#define HEIGHT self.contentView.bounds.size.height

@interface CellOfzhuyi ()
@property (nonatomic, retain) UILabel *label_title;
@property (nonatomic, retain) UILabel *label_des;
@end

@implementation CellOfzhuyi
- (void)dealloc {
    [_label_des release];
    [_label_title release];
    [super dealloc];

}


- (void)passAnyModel:(id)model {
    ModelOfzhuyi *mod = model;

    self.label_title.text = mod.title;
    self.label_des.text = mod.descriptions;

}
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self createViews];
    }
    
    return self;
}

- (void)createViews {
    
    self.dk_backgroundColorPicker = DKColorWithColors([UIColor whiteColor],  [UIColor colorWithRed:0.16 green:0.14 blue:0.13 alpha:1]);
    
    self.label_des = [[UILabel alloc] init];
    self.label_des.numberOfLines = 0;
    [self.contentView addSubview:self.label_des];
    
    self.label_des.dk_textColorPicker = DKColorWithColors([UIColor blackColor], [UIColor whiteColor]);
    
    [self.label_des release];
    
    self.label_title = [[UILabel alloc] init];
    [self.contentView addSubview:self.label_title];
    
    self.label_title.dk_textColorPicker = DKColorWithColors([UIColor blackColor], [UIColor whiteColor]);
    
    [self.label_title release];
    
}
- (void)layoutSubviews {
    [super layoutSubviews];
    
    self.label_title.frame = CGRectMake(10, 10, WIDTH - 20, 30);
    self.label_title.font = [UIFont fontWithName:@"Arial-BoldMT" size:20];
    self.label_des.frame = CGRectMake(10, 10 + 40 + 10, WIDTH - 20, [[self class] heightForLabel:self.label_des.text]);

    
    
}
+ (CGFloat)heightForLabel:(NSString *)text {
    
    CGRect rectview = [text boundingRectWithSize:CGSizeMake(WIDTH - 30, 0) options:NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName:[UIFont systemFontOfSize:17]} context:nil];
    
    return rectview.size.height;
    
    
}

- (CGFloat)heightForCell:(ModelOfzhuyi *)model {
    return  [CellOfzhuyi heightForLabel:model.descriptions];
    
}

@end
